from contifyuser.models import Member
from registration.forms import RegistrationForm
from django import forms
from django.conf import settings
from django import forms
import datetime
from django.contrib.admin.widgets import AdminFileWidget
from utils import activity_module
attrs_dict = { 'class': 'required' }

class RegistrationFormConnectPeople(RegistrationForm):
    
    country = forms.ChoiceField(required=False, choices=settings.COUNTRIES, label='COUNTRY',
                                widget=forms.Select())
    first_name = forms.CharField(required=True, label='FIRST NAME', error_messages={'required': 'Please enter your First Name'},
                                widget=forms.TextInput(attrs={'size':'25'}))
    last_name = forms.CharField(required=True, label='LAST NAME', error_messages={'required': 'Please enter your Last Name'},
                                widget=forms.TextInput(attrs={'size':'25'}))
    city = forms.CharField(max_length=25, required=False, label='CITY', 
                                 widget=forms.TextInput(attrs={'size':'25'}))
    created_date = datetime.date.today()
    
    photo = forms.ImageField(label='Photo', required=False, widget = AdminFileWidget())

    
    def save(self, profile_callback=None):
        new_user = super(RegistrationFormConnectPeople, self).save()
        new_connectpeople_user = Member(user = new_user, country=self.cleaned_data['country'],
                                first_name=self.cleaned_data['first_name'],
                                last_name=self.cleaned_data['last_name'],
                                city=self.cleaned_data['city'],
                                photo=self.cleaned_data['photo'],
                                )
        new_connectpeople_user.save()
        # Save user to graph
        print new_user.username
        activity_module.setUserNode(new_user.username)
        return new_connectpeople_user
    
class photoUploadForm(forms.Form):
    photo = forms.ImageField(label='Photo', required=True, widget = AdminFileWidget())
    
    def save(self, member):
        member.photo =  self.cleaned_data['photo']
        member.save()
        return member
    
class editProfileForm(forms.Form):
    
    country = forms.ChoiceField(required=False, choices=settings.COUNTRIES, label='COUNTRY',
                                widget=forms.Select())
    first_name = forms.CharField(required=True, label='FIRST NAME', error_messages={'required': 'Please enter your First Name'},
                                widget=forms.TextInput(attrs={'size':'20'}))
    last_name = forms.CharField(required=True, label='LAST NAME', error_messages={'required': 'Please enter your Last Name'},
                                widget=forms.TextInput(attrs={'size':'20'}))
    city = forms.CharField(max_length=25, required=False, label='CITY',
                                 widget=forms.TextInput(attrs={'size':'25'}))

    
    def save(self, member):
        member.first_name = self.cleaned_data['first_name']
        member.last_name = self.cleaned_data['last_name']
        member.country = self.cleaned_data['country']
        member.city = self.cleaned_data['city']
        member.save()
        return member